<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .widthF {
            width: 300px;
            height: 300px;
            background: red;
        }

        .widthS {
            width: 100px;
            height: 100px;
            background: gray;
        }

        .father_1 {
            position: relative;
        }

        .son_1 {
            position: absolute;
            margin: auto;
            left: 0;
            right: 0;
            bottom: 0;
            top: 0;
        }
    </style>
</head>

<body>
<!-- 将每个方向上的偏移量设置为0，然后设置margin为auto就可以使得子元素居中 -->
    <div class="father_1 widthF">
        <div class="son_1 widthS">
        </div>
    </div>

</body>

</html>